package o;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.application.pkgmanage.model.reserve.ReserveDbInfo;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.reserve.game.bean.GetOrderedAppsRes;
import com.huawei.appmarket.service.reserve.game.bean.ReserveResponse;
import com.huawei.appmarket.service.webview.base.jssdk.control.FullAppStatus;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import o.dge.d;
import o.epq.e;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public final class efb {
    private static final Object ˋ = new Object();
    private static volatile efb ˏ;
    private int ॱ = 1;

    class a implements cks {
        private dkf ʼ;
        private String ˊ;
        private Context ˋ;
        final /* synthetic */ efb ˎ;
        private int ˏ;
        private efe ॱ;

        private a(efb o_efb, String str, int i, efe o_efe, Context context, dkf o_dkf) {
            this.ˎ = o_efb;
            this.ˊ = str;
            this.ˏ = i;
            this.ॱ = o_efe;
            this.ˋ = context;
            this.ʼ = o_dkf;
        }

        public void enableNetworking() {
            Logger.ˎ("GameReserveManager", "autoDownload = " + this.ˎ.ॱ);
            this.ˎ.ॱ(this.ˊ, this.ˏ, this.ॱ, this.ˋ, this.ʼ, this.ˎ.ॱ);
        }

        public void upgrade() {
        }

        public void ˋ() {
        }
    }

    private efb() {
    }

    public static efb ॱ() {
        if (ˏ == null) {
            synchronized (ˋ) {
                if (ˏ == null) {
                    ˏ = new efb();
                }
            }
        }
        return ˏ;
    }

    public static void ˎ(boolean z, String str, Context context) {
        if (z) {
            dgh.onEvent(new d(context, n.ʽˊ).ˏ(KeyAndValue.NUMBER_01 + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + str + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + UserSession.getInstance().getUserId()).ˋ());
        }
    }

    public void ˎ() {
        ˎ(new e(null));
    }

    public void ˎ(IServerCallBack iServerCallBack) {
        cfw.ˎ(new eez(), iServerCallBack);
    }

    public ResponseBean ˊ() {
        return cfw.ॱ(new eez());
    }

    public void ˋ(Context context, String str, @Nullable dkf o_dkf, efe o_efe) {
        if (TextUtils.isEmpty(str) || context == null) {
            Logger.e("GameReserveManager", "reserve() failed, packageName = " + str);
        } else {
            ˋ(context, str, 0, o_dkf, o_efe);
        }
    }

    public void ˏ(Context context, String str, @Nullable dkf o_dkf, efe o_efe) {
        if (TextUtils.isEmpty(str) || context == null) {
            Logger.e("GameReserveManager", "cancelReserve() failed, packageName = " + str);
        } else {
            ˋ(context, str, 1, o_dkf, o_efe);
        }
    }

    public void ˏ(String str) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("GameReserveManager", "removeReserve() failed, packageName isEmpty");
            return;
        }
        ॱ(str);
        Intent intent = new Intent();
        intent.setAction(e.ॱ);
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(intent);
    }

    public synchronized void ॱ(String str) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("GameReserveManager", "deleteReserveGame() failed, packageName isEmpty");
        } else {
            euc.ˊ().ॱ();
            efg.ˋ().ˊ(str);
            efn.ˊ().ॱ(str);
            dvq.ˊ(ContentManager.getInstant().getContext(), null, 0);
            FullAppStatus fullAppStatus = new FullAppStatus();
            fullAppStatus.ˊ(str);
            fullAppStatus.ˏ(0);
            fullAppStatus.appType_ = 3;
            enf.ˋ().ˊ(fullAppStatus);
            euc.ˊ().ˏ();
        }
    }

    public int ˊ(String str) {
        return eua.ˏ().ॱ(str, 0);
    }

    public void ˏ(String str, int i) {
        eua.ˏ().ˊ(str, i);
    }

    public void ˎ(@NonNull ReserveResponse reserveResponse, String str) {
        euc.ˊ().ॱ();
        ReserveDbInfo reserveDbInfo = new ReserveDbInfo();
        reserveDbInfo.ˋ(str);
        reserveDbInfo.ˎ(reserveResponse.ˏ());
        reserveDbInfo.ॱ(reserveResponse.ॱ());
        reserveDbInfo.ͺ(reserveResponse.ॱ());
        reserveDbInfo.ˊ(reserveResponse.ˋ());
        reserveDbInfo.ˋ(System.currentTimeMillis());
        reserveDbInfo.ˋ(reserveResponse.ˎ());
        reserveDbInfo.ᐝ(reserveResponse.ॱॱ());
        reserveDbInfo.ʼ(reserveResponse.ʼ());
        reserveDbInfo.ˊ(eff.ˊ().ˏ().ˋ());
        efn.ˊ().ॱ(reserveDbInfo.ˋ());
        efn.ˊ().ˏ(reserveDbInfo);
        efg.ˋ().ˋ(reserveDbInfo);
        dvq.ˊ(ContentManager.getInstant().getContext(), null, 0);
        Intent intent = new Intent();
        intent.setAction(e.ॱ);
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(intent);
        FullAppStatus fullAppStatus = new FullAppStatus();
        fullAppStatus.ˊ(reserveResponse.ˋ());
        fullAppStatus.ˏ(1);
        fullAppStatus.appType_ = 3;
        Logger.ˏ("GameReserveManager", "reserveSuccess, packageName = " + reserveResponse.ˋ());
        enf.ˋ().ˊ(fullAppStatus);
        euc.ˊ().ˏ();
    }

    private void ˋ(Context context, String str, int i, @Nullable dkf o_dkf, efe o_efe) {
        if (TextUtils.isEmpty(str) || context == null) {
            Logger.e("GameReserveManager", "reserveWithLogin, packageName = " + str + ", context = " + context);
        } else if (!doo.ˊ(context)) {
            evk.ˋ(context, context.getString(n.ʹˊ), 0).ˋ();
        } else if (!UserSession.getInstance().isLoginSuccessful()) {
            final int i2 = i;
            final String str2 = str;
            final efe o_efe2 = o_efe;
            final Context context2 = context;
            final dkf o_dkf2 = o_dkf;
            eoj.ˋ().ˎ("reserveWithLogin", new AccountBussinessListener(this) {
                final /* synthetic */ efb ʼ;

                public void onAccountBusinessResult(ccp o_ccp) {
                    if (102 == o_ccp.ˎ) {
                        if (i2 != 0 || eqp.ᐝ()) {
                            this.ʼ.ॱ(str2, i2, o_efe2, context2, o_dkf2, 1);
                        } else {
                            this.ʼ.ˏ(str2, i2, o_efe2, context2, o_dkf2);
                        }
                    } else if (DialogButton.CONFIRM == o_ccp.ˎ && o_efe2 != null) {
                        o_efe2.ˋ();
                    }
                    eoj.ˋ().ˊ("reserveWithLogin");
                }
            });
            eod.ॱ(context);
        } else if (i != 0 || eqp.ᐝ()) {
            ॱ(str, i, o_efe, context, o_dkf, 1);
        } else {
            ˏ(str, i, o_efe, context, o_dkf);
        }
    }

    private void ˏ(String str, int i, efe o_efe, Context context, dkf o_dkf) {
        View inflate = LayoutInflater.from(context).inflate(h.ͺͺ, null);
        cku ˏ = cku.ˏ(context, cku.class, context.getResources().getString(n.ʽꜟ), null);
        ˏ.ˎ(context);
        ˏ.ˊ(inflate);
        ˏ.ॱ(-1, context.getString(n.ʽᶥ));
        ˏ.ॱ(-2, context.getString(n.ʾᐝ));
        ˏ.ॱ(new a(str, i, o_efe, context, o_dkf));
        this.ॱ = 1;
        RadioGroup radioGroup = (RadioGroup) inflate.findViewById(j.ꜟʻ);
        ((RadioButton) inflate.findViewById(j.ꞌʼ)).setText(NetWorkUtil.getWifiResId(context, n.ʿʻ));
        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(this) {
            final /* synthetic */ efb ˋ;

            {
                this.ˋ = r1;
            }

            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == j.ꞌʼ) {
                    this.ˋ.ॱ = 1;
                } else if (i == j.Ꞌॱ) {
                    this.ˋ.ॱ = 0;
                }
            }
        });
    }

    private void ॱ(String str, int i, final efe o_efe, Context context, dkf o_dkf, int i2) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("GameReserveManager", "reserve failed, packageName isEmpty.");
            return;
        }
        if (o_dkf != null) {
            o_dkf.ˎ();
        }
        cvt o_efc = new efc();
        o_efc.ॱ(str);
        o_efc.ˎ(i);
        if (i == 0) {
            o_efc.ˏ(i2);
        }
        if (context instanceof Activity) {
            o_efc.setServiceType_(dgm.ˎ((Activity) context));
        }
        cfw.ˎ(o_efc, new IServerCallBack(this) {
            final /* synthetic */ efb ˊ;

            public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if ((responseBean instanceof ReserveResponse) && (o_cvu instanceof efc)) {
                    efc o_efc = (efc) o_cvu;
                    ReserveResponse reserveResponse = (ReserveResponse) responseBean;
                    String ˋ = o_efc.ˋ();
                    String ˏ = o_efc.ˏ();
                    int ॱ = o_efc.ॱ();
                    Logger.ˎ("GameReserveManager", "reserve, packageName = " + ˋ + ", appId = " + ˏ + ", type = " + ॱ + ", rtnCode = " + reserveResponse.getRtnCode_());
                    this.ˊ.ˊ(reserveResponse, ˋ, ˏ, ॱ);
                } else {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(n.ˆॱ));
                    Logger.e("GameReserveManager", "reserve failed, reserveResponse = " + responseBean + ", reserveRequest = " + o_cvu);
                }
                if (o_efe != null) {
                    o_efe.ˎ(o_cvu, responseBean);
                }
            }

            public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            }
        });
    }

    private void ˊ(ReserveResponse reserveResponse, String str, String str2, int i) {
        switch (reserveResponse.getRtnCode_()) {
            case 101001:
            case 101004:
                ˎ(reserveResponse, str, str2, 0);
                return;
            case 101002:
                if (i == 0) {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(n.ʽﾟ));
                    return;
                } else if (i == 1) {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(n.ˌʼ));
                    return;
                } else {
                    return;
                }
            case 101003:
                evk.ˏ(ContentManager.getInstant().getContext().getString(n.ʻꜟ));
                return;
            case 101005:
            case 101006:
                ˎ(reserveResponse, str, str2, 1);
                return;
            case 101007:
                if (i == 0) {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(n.ʿʽ));
                    return;
                } else if (i == 1) {
                    evk.ˏ(ContentManager.getInstant().getContext().getString(n.ˋﹶ));
                    return;
                } else {
                    return;
                }
            default:
                evk.ˏ(ContentManager.getInstant().getContext().getString(n.ˆॱ));
                return;
        }
    }

    private void ˎ(@NonNull ReserveResponse reserveResponse, String str, String str2, int i) {
        if (i == 0) {
            ˎ(reserveResponse, str2);
        } else if (i == 1) {
            evk.ˏ(ContentManager.getInstant().getContext().getString(n.י));
            ˏ(str);
        }
    }

    public void ˎ(Context context, ResponseBean responseBean, boolean z) {
        if (3 == responseBean.getResponseCode()) {
            if (z) {
                evk.ˏ(context.getString(n.ʹˊ));
            }
        } else if (responseBean.getResponseCode() == 0) {
            if (responseBean.getRtnCode_() == 0) {
                efg.ˋ().ˏ(((GetOrderedAppsRes) responseBean).ˋ());
            } else if (responseBean.getRtnCode_() == 2) {
                Logger.e("GameReserveManager", "can not GetOrderedApps:" + responseBean.getResponseCode() + "-" + responseBean.getRtnCode_());
            } else if (z) {
                evk.ˏ(context.getString(n.ॱˉ));
            }
        } else if (ResponseBean.SERVER_DELAY_RETRY == responseBean.getResponseCode()) {
            if (z) {
                evk.ˏ(context.getString(n.ˊᵎ));
            }
        } else if (z) {
            evk.ˏ(context.getString(n.ॱˉ));
        }
    }
}
